@extends('admin.common.main')

@section('css')
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
@endsection
@section('cnt')
    <div class="layui-form layuimini-form" lay-filter="example">
        @csrf
        <div class="layui-form-item" pane="">
            <label class="layui-form-label">选择权限</label>
            @foreach($nodeall as $item)
                <div class="layui-input-block">
                    <input type="checkbox" lay-skin="primary" name="node[]"
{{--                           {{in_array($item['id'],$nodes)??"checked=''"}}--}}
                               @if(in_array($item['id'],$nodes)) checked @endif
                           value="{{$item['id']}}" title="{{$item['name']}}">
                </div>
            @endforeach
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认修改</button>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>
        layui.use(['form','upload','http','table','tableSelect'], function () {
            var form = layui.form,
                layer = layui.layer,
                http  = layui.http,
                $ = layui.$;
            //监听提交
            form.on('submit(saveBtn)', function (data) {
                http.httpajax('{{route('admin.role.nodesave',$role)}}', data.field,"POST",function(res) {
                    if(res.code === 200){
                        layer.msg(res.msg,{time:1000,icon:1},function(){
                            // 关闭弹出层
                            layer.close();
                            window.parent.location.reload();//刷新父页面
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        });
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                });
            });
        });
    </script>
@endsection

